package com.hyh.music.controller;

import com.hyh.music.Result.PageResult;
import com.hyh.music.Result.Result;
import com.hyh.music.Result.Results;
import com.hyh.music.domain.domainDTO.SongDTO;
import com.hyh.music.domain.domainDTO.SongPageDTO;
import com.hyh.music.domain.domainDTO.SongUpdateDTO;
import com.hyh.music.domain.domains.Song;
import com.hyh.music.service.SongService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author hyh
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/song")
public class SongController {

    @Autowired
    SongService songService;

    @GetMapping("/Page")
    public Result<PageResult> PageSelect(SongPageDTO songPageDTO){
        log.info("歌曲分页查询{}",songPageDTO);
        PageResult songs = songService.PageSelect(songPageDTO);
        return Result.success(songs);
    }
    @PostMapping("/addSong")
    public Result addSong(@RequestBody SongDTO songDTO){
        log.info("添加歌曲{}",songDTO);
        songService.addSong(songDTO);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result<Song> selectSongById(@PathVariable Integer id){
        log.info("查询id为{}的歌曲",id);
        Song song = songService.selectById(id);
        return Result.success(song);
    }
    @PutMapping("/update")
    public Result UpdateById(@RequestBody SongUpdateDTO songUpdateDTO){
        log.info("更新歌曲{}",songUpdateDTO.getName());
        songService.update(songUpdateDTO);
        return Result.success();
    }
    @DeleteMapping("/deleteSong")
    public Result DeleteSong(Integer id ){
        log.info("删除id为{}的歌曲",id);
        songService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/allSong")
    public Result<Results> getAllSong(){
        log.info("搜索了所有歌曲");
        Results songsVO = songService.selectAllSongs();
        return Result.success(songsVO);
    }



}
